package ui.common
{
	import adapter.common.CellBaseAdapter;
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	import flash.display.Sprite;

	/**
	 * @author Administrator
	 */
	public class CellBase extends SpriteObject
	{
		private var _mcStatus:MovieClip;
		
		public function CellBase()
		{
			initChilds();
		}
		
		protected function initChilds():void
		{
			_mcStatus = getChildByName("mcCellStatus") as MovieClip;
			if(_mcStatus)
			{
				_mcStatus.stop();
			}
		}
		
		protected function get cellAdapter():CellBaseAdapter
		{
			return adapter  as CellBaseAdapter;
		}
		
		public function set enableHightLight(val:Boolean):void
		{
			if(val)
			{
				addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
				addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			}
			else
			{
				removeEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
				removeEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			}
		}
		
		private function onMouseOver(e:MouseEvent):void
		{
			if(cellAdapter)
			{
				cellAdapter.doHightlight();
			}
		}
		
		private function onMouseOut(e:MouseEvent):void
		{
			if(cellAdapter)
			{
				cellAdapter.doUnhightlight();
			}
		}
		
		public function set enableSelect(val:Boolean):void
		{
			if(val)
			{
				addEventListener(MouseEvent.CLICK, doSelect);
			}
			else
			{
				removeEventListener(MouseEvent.CLICK, doSelect);
			}
		}
		
		private function doSelect(e:MouseEvent):void
		{
			if(cellAdapter)
			{
				cellAdapter.doSelect();
			}
		}
		
		public function onSelect():void
		{
	//		if(_mcStatus)
	//		{
	//			_mcStatus.gotoAndStop(2);
	//		}
		}
		
		public function unSelect():void
		{
			if(_mcStatus)
			{
				_mcStatus.gotoAndStop(1);
			}
		}
		
		public function set acive(val:Boolean):void
		{
			if(_mcStatus)
			{
				if(val)
				{
					_mcStatus.gotoAndStop(2);
				}
				else
				{
					_mcStatus.gotoAndStop(1);
				}
			}
		}
		
		override public function update():void
		{
			super.update();
			
			if(cellAdapter)
			{
				enableHightLight = cellAdapter.highLightEnable;
				enableSelect     = cellAdapter.selectEnable;
			}
		}
	}
}
